package base

import (
	"we-account-api/pkg/response"

	"github.com/gin-gonic/gin"
)

type Controller struct{}

// Success 成功响应
func (b *Controller) Success(c *gin.Context, data interface{}) {
	response.Success(c, data)
}

// Error 错误响应
func (b *Controller) Error(c *gin.Context, message string) {
	response.Error(c, message)
}

// ErrorWithCode 自定义错误码响应
func (b *Controller) ErrorWithCode(c *gin.Context, code int, message string) {
	response.ErrorWithCode(c, code, message)
}

// 获取分页
// GetPagination 获取分页参数
func (b *Controller) GetPagination(c *gin.Context) (int, int) {
	type PaginationRequest struct {
		Page     int `form:"page" binding:"min=1"`
		PageSize int `form:"page_size" binding:"min=1,max=100"`
	}

	var pagination PaginationRequest
	c.ShouldBindQuery(&pagination)
	if pagination.Page == 0 {
		pagination.Page = 1
	}
	if pagination.PageSize == 0 {
		pagination.PageSize = 10
	}
	return pagination.Page, pagination.PageSize
}
